import cv2
import os,time

def getTime():
    return time.strftime("%Y%m%d")

def slice(src,dst):
    time_now = getTime()
    for num,video in enumerate(os.listdir(src)):
        video_path = os.path.join(src,video)
        cap = cv2.VideoCapture(video_path)
        speed = 5
        wait_time = 100
        ret,frame = cap.read()
        i = 0
        save = False
        while ret:
            ret,frame = cap.read()
            i+=1
            key_start = cv2.waitKey(wait_time)
            if key_start == ord("s"):
               save = True
            elif key_start == ord("c"):
                save = False
            elif key_start == ord("q"):
                wait_time = 10
            elif key_start == ord("l"):
                wait_time = 100


            print(key_start)
            if(i%speed==0 and save):
                cv2.imwrite(os.path.join(dst,time_now+str(num).zfill(2)+str(int(i/speed)).zfill(4))+".jpg",frame )
                print(os.path.join(dst,time_now+str(num).zfill(2)+str(int(i/speed)).zfill(4))+".jpg")
            if(ret):
                cv2.imshow("frame",frame)
                cv2.waitKey(1)

def main():
    src = "D:\py-project\\1"
    dst = os.path.join(os.getcwd(),"images")
    slice(src,dst)

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    main()

